package com.qf.openapi.web.master.vo;
import com.qf.openapi.web.master.utils.Constants;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVo {
    // 代表后端接口处理状态
    private String code;

    // 代表状态码的具体含义
    private String msg;

    // 封装接口返回的数据
    private Object data;

    public static ResultVo getInstance(String code, String msg) {
        final ResultVo resultVo = new ResultVo();
        resultVo.setCode(code);
        resultVo.setMsg(msg);
        return resultVo;
    }

    public static ResultVo getInstance(String code, String msg, Object data) {
        final ResultVo resultVo = new ResultVo();
        resultVo.setCode(code);
        resultVo.setMsg(msg);
        resultVo.setData(data);
        return resultVo;
    }

    public static ResultVo ok(Object data) {
        final ResultVo resultVo = new ResultVo();
        resultVo.setCode(Constants.COMMON_SUCCESS_CODE);
        resultVo.setMsg(Constants.COMMON_SUCCESS_MSG);
        resultVo.setData(data);
        return resultVo;
    }

    public static ResultVo ok() {
        final ResultVo resultVo = new ResultVo();
        resultVo.setCode(Constants.COMMON_SUCCESS_CODE);
        resultVo.setMsg(Constants.COMMON_SUCCESS_MSG);
        return resultVo;
    }

    public static ResultVo fail() {
        final ResultVo resultVo = new ResultVo();
        resultVo.setCode(Constants.COMMON_ERROR_CODE);
        resultVo.setMsg(Constants.COMMON_ERROR_MSG);
        return resultVo;
    }

    public static ResultVo fail(Object data) {
        final ResultVo resultVo = new ResultVo();
        resultVo.setCode(Constants.COMMON_ERROR_CODE);
        resultVo.setMsg(Constants.COMMON_ERROR_MSG);
        resultVo.setData(data);
        return resultVo;
    }

    public static ResultVo failWithErrorMsg(String msg) {
        final ResultVo resultVo = new ResultVo();
        resultVo.setCode(Constants.COMMON_ERROR_CODE);
        resultVo.setMsg(msg);
        return resultVo;
    }
}
